package com.wf.course.web.controller.goods;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.utils.page.PageBean;
import com.wf.course.model.goods.ShoppingCart;
import com.wf.course.service.IShoppingCartService;
/**
 * 
 * @content 列表Controller
 */
@RequestMapping("shoppingCart")
@Controller
public class ShoppingCartController {

	@Autowired
	private IShoppingCartService shoppingCartService;

	/**
	 * 列表展示
	 * @param pageNo
	 * @param pageSize
	 * @param goodsName
	 * @param model
	 * @return
	 */
	@RequestMapping("shoppingCartList")
	public String goodsTypelist(@RequestParam(value = "pageNo", required = false) Integer pageNo,
			@RequestParam(value = "pageSize", required = false) Integer pageSize,
			@RequestParam(value = "goodsName", required = false) String goodsName, 
			@RequestParam(value = "userName", required = false) String userName, 
			Model model) {

		// 组装一个查询条件的map
		Map<String, Object> cons = new HashMap<String, Object>();
		cons.put("goodsName", goodsName);
		cons.put("userName", userName);
		PageBean<ShoppingCart> pageBean = new PageBean<ShoppingCart>(pageNo, pageSize, null, cons);
		pageBean.setUrl("shoppingCart/shoppingCartList");
		this.shoppingCartService.indexInfo(pageBean);
		
		model.addAttribute("page", pageBean);
		return "goods/shoppingCartList";
	}

	/**
	 *  修改和新增页面数据初始化
	 * 
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping("pageLoad/{id}")
	public String downLoadById(@PathVariable("id") Integer id, Model model) {
		 
		if (id != null && id != 0) {
			ShoppingCart shoppingCart = shoppingCartService.queryShoppingCartById(id);
			model.addAttribute("shoppingCart", shoppingCart);
			model.addAttribute("type", "upd");
		}else{
			model.addAttribute("type", "add");
		}
		 
		return "goods/shoppingCartEdit";
	}

	 
	 

}
